package com.yaorange.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yaorange.common.log.annotation.Log;
import com.yaorange.common.log.enums.BusinessType;
import com.yaorange.common.security.annotation.RequiresPermissions;
import com.yaorange.teaching.domain.YaKnowledgePoints;
import com.yaorange.teaching.service.IYaKnowledgePointsService;
import com.yaorange.common.core.web.controller.BaseController;
import com.yaorange.common.core.web.domain.AjaxResult;
import com.yaorange.common.core.utils.poi.ExcelUtil;
import com.yaorange.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 知识点Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/knowledge_points")
public class YaKnowledgePointsController extends BaseController
{
    @Autowired
    private IYaKnowledgePointsService yaKnowledgePointsService;

    /**
     * 查询知识点列表
     */
    @RequiresPermissions("teaching:knowledge_points:list")
    @GetMapping("/list")
    public TableDataInfo list(YaKnowledgePoints yaKnowledgePoints)
    {
        startPage();
        List<YaKnowledgePoints> list = yaKnowledgePointsService.selectYaKnowledgePointsList(yaKnowledgePoints);
        return getDataTable(list);
    }

    /**
     * 导出知识点列表
     */
    @RequiresPermissions("teaching:knowledge_points:export")
    @Log(title = "知识点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaKnowledgePoints yaKnowledgePoints)
    {
        List<YaKnowledgePoints> list = yaKnowledgePointsService.selectYaKnowledgePointsList(yaKnowledgePoints);
        ExcelUtil<YaKnowledgePoints> util = new ExcelUtil<YaKnowledgePoints>(YaKnowledgePoints.class);
        util.exportExcel(response, list, "知识点数据");
    }

    /**
     * 获取知识点详细信息
     */
    @RequiresPermissions("teaching:knowledge_points:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaKnowledgePointsService.selectYaKnowledgePointsById(id));
    }

    /**
     * 新增知识点
     */
    @RequiresPermissions("teaching:knowledge_points:add")
    @Log(title = "知识点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YaKnowledgePoints yaKnowledgePoints)
    {
        return toAjax(yaKnowledgePointsService.insertYaKnowledgePoints(yaKnowledgePoints));
    }

    /**
     * 修改知识点
     */
    @RequiresPermissions("teaching:knowledge_points:edit")
    @Log(title = "知识点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaKnowledgePoints yaKnowledgePoints)
    {
        return toAjax(yaKnowledgePointsService.updateYaKnowledgePoints(yaKnowledgePoints));
    }

    /**
     * 删除知识点
     */
    @RequiresPermissions("teaching:knowledge_points:remove")
    @Log(title = "知识点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaKnowledgePointsService.deleteYaKnowledgePointsByIds(ids));
    }

    /**
     * 批量导入知识点
     */
    @RequiresPermissions("teaching:knowledge_points:add")
    @Log(title = "批量导入 知识点", businessType = BusinessType.INSERT)
    @PostMapping("/import")
    public AjaxResult importBatch(@RequestPart("file") MultipartFile file) {
        return AjaxResult.success(yaKnowledgePointsService.parseAndSave(file));
    }

}
